/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ErrorPanel.java
 *
 * Created on 23 janv. 2012, 22:19:24
 */
package com.jme3.gde.gui.multiview;

import java.awt.Component;
import javax.swing.DefaultListCellRenderer;
import javax.swing.DefaultListModel;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.SwingConstants;

/**
 *
 * @author Nehon
 */
public class ErrorPanel extends java.awt.Panel {
    
    private DefaultListModel errors = new DefaultListModel();
    private static ImageIcon fatalImage = null, nonFatalImage = null;

    /** Creates new form ErrorPanel */
    public ErrorPanel() {
        initComponents();
        jList1.setCellRenderer(new DefaultListCellRenderer() {

            @Override
            public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
                super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
                if (value instanceof JLabel) {
                    setIcon(((JLabel) value).getIcon());
                    setText(((JLabel) value).getText());
                }
                return this;
            }
        });
    }
    
    private static ImageIcon getFatalErrorIcon() {
        if (fatalImage == null) {
            fatalImage = new ImageIcon(ErrorPanel.class.getResource("/com/jme3/gde/gui/resources/icons/error.png")); //NOI18N
        }
        return fatalImage;
    }
    
    private static ImageIcon getNonfatalErrorIcon() {
        if (nonFatalImage == null) {
            nonFatalImage = new ImageIcon(ErrorPanel.class.getResource("/com/jme3/gde/gui/resources/icons/warning.png")); //NOI18N
        }
        return nonFatalImage;
    }

    public void addError(String error) {
         errors.addElement(new JLabel(
              error,
              getFatalErrorIcon(),
              SwingConstants.LEFT));
      
    }
   
    public void addWarning(String error) {
         errors.addElement(new JLabel(
              error,
              getNonfatalErrorIcon(),
              SwingConstants.LEFT));
      
    }
    
    public void clear(){
        errors.clear();
    }
 

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jList1 = new javax.swing.JList();
        jLabel2 = new javax.swing.JLabel();

        jLabel1.setText(org.openide.util.NbBundle.getMessage(ErrorPanel.class, "ErrorPanel.jLabel1.text")); // NOI18N

        setLayout(new java.awt.BorderLayout());

        jList1.setModel(errors);
        jScrollPane1.setViewportView(jList1);

        add(jScrollPane1, java.awt.BorderLayout.CENTER);

        jLabel2.setBackground(new java.awt.Color(200, 200, 200));
        jLabel2.setText(org.openide.util.NbBundle.getMessage(ErrorPanel.class, "ErrorPanel.jLabel2.text")); // NOI18N
        add(jLabel2, java.awt.BorderLayout.NORTH);
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JList jList1;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration//GEN-END:variables
}
